public class Solution {
    public boolean isPalindrome(String s) {
        String str1 = s.toLowerCase();
        StringBuilder str2 = new StringBuilder(s);

        for (int i = 0; i < str2.length(); i++) {
            if (str2.charAt(i) < 'a' || str2.charAt(i) > 'z') {
                str2.setCharAt(i, ' ');
            }
        }
        str2.replace(0, str2.length(), str2.toString().replace(" ", ""));
        str1 = str2.toString();
        return str1.equals(str2.reverse().toString());
    }
}
